package org.ruanjj.multithread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

//线程池进行创建
public class ThreadDemo4 {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(2);
        ThreadPoolExecutor poolExecutor = (ThreadPoolExecutor) service;

        poolExecutor.execute(new EvenNumber());
        poolExecutor.execute(new OddNumber());

        poolExecutor.shutdown();
    }
}

class EvenNumber implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i <100; i++){
            if(i % 2 == 0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}


class OddNumber implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i <100; i++){
            if(i % 2 == 1){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}
